/* *****************************************************************************
*
*	danizone.ch
*
*	Developer:		mda010
*	Creation date:	May 6, 2012 11:09:59 PM
*	
*	Project name:	HomegrownCuisine
*	File name:		SeasonService.java
*
*	Copyrights (C) 2012 @danizone.ch
*
*   This program is free software; you can redistribute it and/or modify
*	it under the terms of the GNU General Public License as published by
*	the Free Software Foundation; either version 2 of the License, or
*	(at your option) any later version.
*
*	This program is distributed in the hope that it will be useful,
*	but WITHOUT ANY WARRANTY; without even the implied warranty of
*	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
*	GNU General Public License for more details.
*
*	Change history:	[developer]; [date];[reason for change]
*
*					mda010; May 6, 2012; created
*
***************************************************************************** */
package ch.zhaw.hgc.services.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import ch.zhaw.hgc.daos.ISeasonDao;
import ch.zhaw.hgc.daos.IUserAccountDao;
import ch.zhaw.hgc.entities.Season;
import ch.zhaw.hgc.entities.UserAccount;
import ch.zhaw.hgc.services.ISeasonService;
import ch.zhaw.hgc.services.IUserAccountService;

import com.google.appengine.api.datastore.Key;

/**
 * Implementation note goes here!
 */
@Service
public class UserAccountService implements IUserAccountService{

	@Autowired
	private IUserAccountDao userAccountDao;
	
	@Override
	@Transactional(readOnly=true)
	public UserAccount findByKey(Key key){

		return userAccountDao.findById(key);
	}

	@Override
	@Transactional(readOnly=true)
	public List<UserAccount> findAll(){

		return userAccountDao.findAll();
	}

	@Override
	@Transactional
	public UserAccount save(UserAccount userAccount){

		if(userAccount.getKey() == null){
			
			userAccount = userAccountDao.create(userAccount);
		}
		else{
			
			userAccountDao.update(userAccount);
		}
		
		return userAccount;
	}

	@Override
	@Transactional
	public void remove(UserAccount userAccount){

		userAccountDao.remove(userAccount);
	}
}